package com.zzptc.tkfate.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.zzptc.tkfate.R;
import com.zzptc.tkfate.databinding.RecipeItemBinding;
import com.zzptc.tkfate.entity.ResultsBean;

import java.util.List;

public class MyRecyclerviewAdapter extends RecyclerView.Adapter<MyRecyclerviewAdapter.ViewHolder> {
    private List<ResultsBean> reciptesList;
    private Context context;

    public MyRecyclerviewAdapter(List<ResultsBean> reciptesList,Context context){
        this.reciptesList=reciptesList;
        this.context=context;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        RecipeItemBinding binding=DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
                R.layout.recipe_item,null,false);
        return new ViewHolder(binding);
    }

    @Override//绑定数据
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        //将数据拿出来
        ResultsBean resultsBean=reciptesList.get(position);

        holder.recipeItemBinding.tvTitle.setText(resultsBean.getTitle());
        Glide.with(context)
                .load(resultsBean.getCover())
                .into(holder.recipeItemBinding.ivPic);

    }

    @Override
    public int getItemCount() {
        return reciptesList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private RecipeItemBinding recipeItemBinding;
        public ViewHolder(@NonNull RecipeItemBinding recipeItemBinding) {
            super(recipeItemBinding.getRoot());
            this.recipeItemBinding=recipeItemBinding;
        }
    }
}
